package com.xiaoyilin.consumer;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
@RabbitListener(queues = "my.topic.queue")
public class TopicQueueConsumerAck {

    @RabbitHandler
    public void process(String msg, Message message, Channel channel) throws IOException {
        System.out.println(message.getMessageProperties().getMessageId());
        System.out.println(msg);
        // 采用手动应答模式
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
        System.out.println("消费者 " + new String(message.getBody()));

    }


}
